﻿using FluentNHibernate.Mapping;

namespace TaskKernel.Domain.Nhibernate.Mappings
{
    public class AccountMap : ClassMap<Account>
    {
        public AccountMap()
        {
            Table("task_Accounts");
            Id(x => x.UID, "GID").GeneratedBy.GuidNative();
            Map(x => x.Login, "Login");
            Map(x => x.FullName, "FullName");
            Map(x => x.Mail, "Mail");
            Map(x => x.Fired, "Fired");
            Map(x => x.Phone, "Phone").Nullable();
            Map(x => x.JobTitle, "Title").Nullable();
            Map(x => x.DepartmentName, "Department").Nullable();
            HasManyToMany(x => x.MasterAccounts)
                .ParentKeyColumn("AccountGID")
                .ChildKeyColumn("ManagerGID")
                .Table("task_AccountsManagers")
                .Cascade.All().LazyLoad().AsSet()
                .Access.ReadOnlyPropertyThroughCamelCaseField();
            HasManyToMany(x => x.SlaveAccounts)
                .ParentKeyColumn("ManagerGID")
                .ChildKeyColumn("AccountGID")
                .Table("task_AccountsManagers")
                .Cascade.All().LazyLoad().AsSet()
                .Access.ReadOnlyPropertyThroughCamelCaseField();
        }
    }
}